// 商品管理脚本
$(function() {
	$('#messagegrid').datagrid({
		title : '您所在的位置：行业/市场管理模块&nbsp;&nbsp;--&gt;&gt;&nbsp;&nbsp;行业类别&nbsp;&nbsp;--&gt;&gt;&nbsp;&nbsp;行业类别维护',
		idField : 'id',
		width : 1000,
		height : 400,
		nowrap : false,
		striped : true,
		collapsible : false,
		url : '../category/category_showChildren.shtml?id='+id+'&t='+(new Date()).getTime().toString(36),
		frozenColumns : [[{
					field : 'ck',
					title : '选择',
					checkbox : true
				}]],
		columns : [[{
					field : 'name',
					title : '名称',
					align : 'center',
					width : 162
				},{
					field : 'goodsOrder',
					title : '类别序号',
					formatter : function(value, rec) {
						if(value=='')return "0";
					    if(value==null)return "0";
					    return  value;
					},
					align : 'center',
					width : 162
				}, {
					field : 'id',
					title : '操作',
					align : 'center',
					width : 170,
					sortable : true,
					formatter : function(value, rec) {
						var id = rec.id;
					if (rec.id == undefined)
							return null;
						else
							return '<span style="color:red" id="operate"><a href="javascript:modify(\''+id+'\')">修改</a>&nbsp;&nbsp;&nbsp;<a href="javascript:del(\''+id+'\')">删除</a>&nbsp;&nbsp;&nbsp;<a href="javascript:viewChildrenInfo(\''+id+'\')">查看关联信息</a></span>';
					}
				}
		]],
		pagination : true,
		rownumbers : true,
		toolbar : [{
					id : 'btnadd',
					text : '添加子类别',
					iconCls : 'icon-add',
					handler : function() {
						$(this).attr("href", '../category/category_showChildInfo.shtml?menuCls=31&pid='+id);
					}
				},'-',{
					id : 'btnback',
					text : '返回上一层',
					iconCls : 'icon-back',
					handler : function() {
						$(this).attr("href", '../goods/category_list.jsp?menuCls=31');
					}
				}]
	}

	);


});

function del(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	if (confirm("确定删除此条信息吗?")) {
		var url1 = "../category/category_delete.shtml?level=2";
		$.ajax({
					url : url1,
					data : "id=" + id,
					success : function(msg) {
						if(msg=="1"){
							alert("删除成功");							
						}else if(msg=="3"){
							alert("该类别下拥有产品种类或产品，禁止删除。");
						}else{
							alert("删除失败");
						}
						$('#messagegrid').datagrid("reload");
					}
				});

	}
}
function modify(id) {
	if (id == "undefined") {
		alert("此条记录已删除");
		return;
	}
	window.location.href = "../category/category_showChildInfo.shtml?menuCls=31&id=" + id;
}

function viewChildrenInfo(categoryId) {
	if (categoryId == "undefined") {
		alert("此条记录已删除");
		return;
	}
	window.location.href = "../goods/category_childrenInfo.jsp?menuCls=31&id=" + categoryId+'&categoryId='+id;
}

